package pe.com.trener.layer.model.persistence.daoimpl;

/**
 * @author:   Oscar Erick Candela Carbajal
 * @rol:	  Analista Programador
 * @proyecto: Portal Trener
 *
 */

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.struts.util.LabelValueBean;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import pe.com.trener.layer.model.persistence.dao.AreaDao;
import pe.com.trener.layer.model.pojo.Area;

public class AreaDaoImpl extends HibernateDaoSupport implements AreaDao {

	@SuppressWarnings("unchecked")
	public List<Area> buscarTodos() throws Exception {
		try {   
			List<Area> resultQuery = new ArrayList<Area>();
			List resultLabelValue = new ArrayList();
			HibernateTemplate ht = getHibernateTemplate();
		 		        
	        String queryString = " from " +
								 " Area o ";
	        
	        resultQuery = (List<Area>)ht.find(queryString);
	        	        
	        Iterator<Area> it = resultQuery.iterator();
	        
	        while (it.hasNext()) {
	        	Area objectModel = (Area)it.next();
	        	LabelValueBean objectLabelValueBean = new LabelValueBean();
	        	objectLabelValueBean.setLabel(objectModel.getDescripcion());
	        	objectLabelValueBean.setValue(objectModel.getCodigoArea().toString());
	        	resultLabelValue.add(objectLabelValueBean);
	        }
	        return resultLabelValue;
		} catch(Exception e) {
			e.printStackTrace();
			throw new Exception(e);
		} finally {		
		}        
	}

}